package service

import (
	"gin/CloudRestaurant/dao"
	"gin/CloudRestaurant/tool"
	"github.com/gin-gonic/gin"
)

type UserService struct {

}

// 登录服务
func (us *UserService)Login(username string,password string,context *gin.Context) string {
	// 查找信息
	md := dao.UserDao{tool.DBEngine}
	result := md.QuerByUP(username,password)
	if result.Id == 0 { //查找失败
		context.Header("token","")
		return ""
	}
	// 获得生成的token
	token,_  := tool.GenerateToken(result)
	context.Header("token",token)

	return token
}